1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Image; 26 27 private import gdk.PaintableIF; 28 private import gdkpixbuf.Pixbuf; 29 private import gio.IconIF; 30 private import glib.ConstructionException; 31 private import glib.Str; 32 private import glib.c.functions; 33 private import gobject.ObjectG; 34 private import gtk.Widget; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 38 39 /** 40 * The `GtkImage` widget displays an image. 41 * 42 *  43 * 44 * Various kinds of object can be displayed as an image; most typically, 45 * you would load a `GdkTexture` from a file, using the convenience function 46 * [ctor@Gtk.Image.new_from_file], for instance: 47 * 48 * ```c 49 * GtkWidget *image = gtk_image_new_from_file ("myfile.png"); 50 * ``` 51 * 52 * If the file isn’t loaded successfully, the image will contain a 53 * “broken image” icon similar to that used in many web browsers. 54 * 55 * If you want to handle errors in loading the file yourself, 56 * for example by displaying an error message, then load the image with 57 * [ctor@Gdk.Texture.new_from_file], then create the `GtkImage` with 58 * [ctor@Gtk.Image.new_from_paintable]. 59 * 60 * Sometimes an application will want to avoid depending on external data 61 * files, such as image files. See the documentation of `GResource` inside 62 * GIO, for details. In this case, [property@Gtk.Image:resource], 63 * [ctor@Gtk.Image.new_from_resource], and [method@Gtk.Image.set_from_resource] 64 * should be used. 65 * 66 * `GtkImage` displays its image as an icon, with a size that is determined 67 * by the application. See [class@Gtk.Picture] if you want to show an image 68 * at is actual size. 69 * 70 * ## CSS nodes 71 * 72 * `GtkImage` has a single CSS node with the name `image`. The style classes 73 * `.normal-icons` or `.large-icons` may appear, depending on the 74 * [property@Gtk.Image:icon-size] property. 75 * 76 * ## Accessibility 77 * 78 * `GtkImage` uses the `GTK_ACCESSIBLE_ROLE_IMG` role. 79 */ 80 public class Image : Widget 81 { 82 /** the main Gtk struct */ 83 protected GtkImage* gtkImage; 84 85 /** Get the main Gtk struct */ 86 public GtkImage* getImageStruct(bool transferOwnership = false) 87 { 88 if (transferOwnership) 89 ownedRef = false; 90 return gtkImage; 91 } 92 93 /** the main Gtk struct as a void* */ 94 protected override void* getStruct() 95 { 96 return cast(void*)gtkImage; 97 } 98 99 /** 100 * Sets our main struct and passes it to the parent class. 101 */ 102 public this (GtkImage* gtkImage, bool ownedRef = false) 103 { 104 this.gtkImage = gtkImage; 105 super(cast(GtkWidget*)gtkImage, ownedRef); 106 } 107 108 109 /** */ 110 public static GType getType() 111 { 112 return gtk_image_get_type(); 113 } 114 115 /** 116 * Creates a new empty `GtkImage` widget. 117 * 118 * Returns: a newly created `GtkImage` widget. 119 * 120 * Throws: ConstructionException GTK+ fails to create the object. 121 */ 122 public this() 123 { 124 auto __p = gtk_image_new(); 125 126 if(__p is null) 127 { 128 throw new ConstructionException("null returned by new"); 129 } 130 131 this(cast(GtkImage*) __p); 132 } 133 134 /** 135 * Creates a new `GtkImage` displaying the file @filename. 136 * 137 * If the file isn’t found or can’t be loaded, the resulting `GtkImage` 138 * will display a “broken image” icon. This function never returns %NULL, 139 * it always returns a valid `GtkImage` widget. 140 * 141 * If you need to detect failures to load the file, use 142 * [ctor@Gdk.Texture.new_from_file] to load the file yourself, 143 * then create the `GtkImage` from the texture. 144 * 145 * The storage type (see [method@Gtk.Image.get_storage_type]) 146 * of the returned image is not defined, it will be whatever 147 * is appropriate for displaying the file. 148 * 149 * Params: 150 * filename = a filename 151 * 152 * Returns: a new `GtkImage` 153 * 154 * Throws: ConstructionException GTK+ fails to create the object. 155 */ 156 public this(string filename) 157 { 158 auto __p = gtk_image_new_from_file(Str.toStringz(filename)); 159 160 if(__p is null) 161 { 162 throw new ConstructionException("null returned by new_from_file"); 163 } 164 165 this(cast(GtkImage*) __p); 166 } 167 168 /** 169 * Creates a `GtkImage` displaying an icon from the current icon theme. 170 * 171 * If the icon name isn’t known, a “broken image” icon will be 172 * displayed instead. If the current icon theme is changed, the icon 173 * will be updated appropriately. 174 * 175 * Params: 176 * icon = an icon 177 * 178 * Returns: a new `GtkImage` displaying the themed icon 179 * 180 * Throws: ConstructionException GTK+ fails to create the object. 181 */ 182 public this(IconIF icon) 183 { 184 auto __p = gtk_image_new_from_gicon((icon is null) ? null : icon.getIconStruct()); 185 186 if(__p is null) 187 { 188 throw new ConstructionException("null returned by new_from_gicon"); 189 } 190 191 this(cast(GtkImage*) __p); 192 } 193 194 /** 195 * Creates a new `GtkImage` displaying @paintable. 196 * 197 * The `GtkImage` does not assume a reference to the paintable; you still 198 * need to unref it if you own references. `GtkImage` will add its own 199 * reference rather than adopting yours. 200 * 201 * The `GtkImage` will track changes to the @paintable and update 202 * its size and contents in response to it. 203 * 204 * Params: 205 * paintable = a `GdkPaintable` 206 * 207 * Returns: a new `GtkImage` 208 * 209 * Throws: ConstructionException GTK+ fails to create the object. 210 */ 211 public this(PaintableIF paintable) 212 { 213 auto __p = gtk_image_new_from_paintable((paintable is null) ? null : paintable.getPaintableStruct()); 214 215 if(__p is null) 216 { 217 throw new ConstructionException("null returned by new_from_paintable"); 218 } 219 220 this(cast(GtkImage*) __p); 221 } 222 223 /** 224 * Creates a new `GtkImage` displaying @pixbuf. 225 * 226 * The `GtkImage` does not assume a reference to the pixbuf; you still 227 * need to unref it if you own references. `GtkImage` will add its own 228 * reference rather than adopting yours. 229 * 230 * This is a helper for [ctor@Gtk.Image.new_from_paintable], and you can't 231 * get back the exact pixbuf once this is called, only a texture. 232 * 233 * Note that this function just creates an `GtkImage` from the pixbuf. 234 * The `GtkImage` created will not react to state changes. Should you 235 * want that, you should use [ctor@Gtk.Image.new_from_icon_name]. 236 * 237 * Params: 238 * pixbuf = a `GdkPixbuf` 239 * 240 * Returns: a new `GtkImage` 241 * 242 * Throws: ConstructionException GTK+ fails to create the object. 243 */ 244 public this(Pixbuf pixbuf) 245 { 246 auto __p = gtk_image_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct()); 247 248 if(__p is null) 249 { 250 throw new ConstructionException("null returned by new_from_pixbuf"); 251 } 252 253 this(cast(GtkImage*) __p); 254 } 255 256 /** 257 * Resets the image to be empty. 258 */ 259 public void clear() 260 { 261 gtk_image_clear(gtkImage); 262 } 263 264 /** 265 * Gets the `GIcon` being displayed by the `GtkImage`. 266 * 267 * The storage type of the image must be %GTK_IMAGE_EMPTY or 268 * %GTK_IMAGE_GICON (see [method@Gtk.Image.get_storage_type]). 269 * The caller of this function does not own a reference to the 270 * returned `GIcon`. 271 * 272 * Returns: a `GIcon` 273 */ 274 public IconIF getGicon() 275 { 276 auto __p = gtk_image_get_gicon(gtkImage); 277 278 if(__p is null) 279 { 280 return null; 281 } 282 283 return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p); 284 } 285 286 /** 287 * Gets the icon name and size being displayed by the `GtkImage`. 288 * 289 * The storage type of the image must be %GTK_IMAGE_EMPTY or 290 * %GTK_IMAGE_ICON_NAME (see [method@Gtk.Image.get_storage_type]). 291 * The returned string is owned by the `GtkImage` and should not 292 * be freed. 293 * 294 * Returns: the icon name 295 */ 296 public string getIconName() 297 { 298 return Str.toString(gtk_image_get_icon_name(gtkImage)); 299 } 300 301 /** 302 * Gets the icon size used by the @image when rendering icons. 303 * 304 * Returns: the image size used by icons 305 */ 306 public GtkIconSize getIconSize() 307 { 308 return gtk_image_get_icon_size(gtkImage); 309 } 310 311 /** 312 * Gets the image `GdkPaintable` being displayed by the `GtkImage`. 313 * 314 * The storage type of the image must be %GTK_IMAGE_EMPTY or 315 * %GTK_IMAGE_PAINTABLE (see [method@Gtk.Image.get_storage_type]). 316 * The caller of this function does not own a reference to the 317 * returned paintable. 318 * 319 * Returns: the displayed paintable 320 */ 321 public PaintableIF getPaintable() 322 { 323 auto __p = gtk_image_get_paintable(gtkImage); 324 325 if(__p is null) 326 { 327 return null; 328 } 329 330 return ObjectG.getDObject!(PaintableIF)(cast(GdkPaintable*) __p); 331 } 332 333 /** 334 * Gets the pixel size used for named icons. 335 * 336 * Returns: the pixel size used for named icons. 337 */ 338 public int getPixelSize() 339 { 340 return gtk_image_get_pixel_size(gtkImage); 341 } 342 343 /** 344 * Gets the type of representation being used by the `GtkImage` 345 * to store image data. 346 * 347 * If the `GtkImage` has no image data, the return value will 348 * be %GTK_IMAGE_EMPTY. 349 * 350 * Returns: image representation being used 351 */ 352 public GtkImageType getStorageType() 353 { 354 return gtk_image_get_storage_type(gtkImage); 355 } 356 357 /** 358 * Sets a `GtkImage` to show a file. 359 * 360 * See [ctor@Gtk.Image.new_from_file] for details. 361 * 362 * Params: 363 * filename = a filename 364 */ 365 public void setFromFile(string filename) 366 { 367 gtk_image_set_from_file(gtkImage, Str.toStringz(filename)); 368 } 369 370 /** 371 * Sets a `GtkImage` to show a `GIcon`. 372 * 373 * See [ctor@Gtk.Image.new_from_gicon] for details. 374 * 375 * Params: 376 * icon = an icon 377 */ 378 public void setFromGicon(IconIF icon) 379 { 380 gtk_image_set_from_gicon(gtkImage, (icon is null) ? null : icon.getIconStruct()); 381 } 382 383 /** 384 * Sets a `GtkImage` to show a named icon. 385 * 386 * See [ctor@Gtk.Image.new_from_icon_name] for details. 387 * 388 * Params: 389 * iconName = an icon name 390 */ 391 public void setFromIconName(string iconName) 392 { 393 gtk_image_set_from_icon_name(gtkImage, Str.toStringz(iconName)); 394 } 395 396 /** 397 * Sets a `GtkImage` to show a `GdkPaintable`. 398 * 399 * See [ctor@Gtk.Image.new_from_paintable] for details. 400 * 401 * Params: 402 * paintable = a `GdkPaintable` 403 */ 404 public void setFromPaintable(PaintableIF paintable) 405 { 406 gtk_image_set_from_paintable(gtkImage, (paintable is null) ? null : paintable.getPaintableStruct()); 407 } 408 409 /** 410 * Sets a `GtkImage` to show a `GdkPixbuf`. 411 * 412 * See [ctor@Gtk.Image.new_from_pixbuf] for details. 413 * 414 * Note: This is a helper for [method@Gtk.Image.set_from_paintable], 415 * and you can't get back the exact pixbuf once this is called, 416 * only a paintable. 417 * 418 * Params: 419 * pixbuf = a `GdkPixbuf` or `NULL` 420 */ 421 public void setFromPixbuf(Pixbuf pixbuf) 422 { 423 gtk_image_set_from_pixbuf(gtkImage, (pixbuf is null) ? null : pixbuf.getPixbufStruct()); 424 } 425 426 /** 427 * Sets a `GtkImage` to show a resource. 428 * 429 * See [ctor@Gtk.Image.new_from_resource] for details. 430 * 431 * Params: 432 * resourcePath = a resource path 433 */ 434 public void setFromResource(string resourcePath) 435 { 436 gtk_image_set_from_resource(gtkImage, Str.toStringz(resourcePath)); 437 } 438 439 /** 440 * Suggests an icon size to the theme for named icons. 441 * 442 * Params: 443 * iconSize = the new icon size 444 */ 445 public void setIconSize(GtkIconSize iconSize) 446 { 447 gtk_image_set_icon_size(gtkImage, iconSize); 448 } 449 450 /** 451 * Sets the pixel size to use for named icons. 452 * 453 * If the pixel size is set to a value != -1, it is used instead 454 * of the icon size set by [method@Gtk.Image.set_from_icon_name]. 455 * 456 * Params: 457 * pixelSize = the new pixel size 458 */ 459 public void setPixelSize(int pixelSize) 460 { 461 gtk_image_set_pixel_size(gtkImage, pixelSize); 462 } 463 }